var province=$("#province"),city=$("#city"),town=$("#town");

function addEle(ele,value,name){
    var optionStr="";
    optionStr="<option value="+value+">"+name+"</option>";
    ele.append(optionStr);
}
function removeEle(ele){
    ele.find("option").remove();
    var optionStar="<option value=''>"+"请选择"+"</option>";
    ele.append(optionStar);
}
var provinceText,cityText,cityItem;
province.on("change",function(){
    id=$(this).val();
    vm.queryId=id;
    $.post((window.localStorage.getItem("baseURL")?window.localStorage.getItem("baseURL"):"") + 'sys/sysarea/areaLevels',{pId:id},function (data) {
        $.each(data,function(i,item){
            addEle(city,item.id,item.name);
        });
    });
    removeEle(city);
    removeEle(town);
});
town.on("change",function(){
    id=$(this).val();
    vm.queryId=id;
    if(!id){
        city.val("");
        province.val("");
    }

});

city.on("change",function(){
    removeEle(town);
    id=$(this).val();
    vm.queryId=id;
    $.post((window.localStorage.getItem("baseURL")?window.localStorage.getItem("baseURL"):"") + 'sys/sysarea/areaLevels',{pId:id},function (data) {
        $.each(data,function(i,item){
            addEle(town,item.id,item.name);
        });
    });

    if(!id){
        town.val("");
        province.val("");
    }
});

(function () {
    $.post((window.localStorage.getItem("baseURL")?window.localStorage.getItem("baseURL"):"") + 'sys/sysarea/areaLevels',{pId:"0"},function (data) {
        $.each(data,function(i,item){
            addEle(province,item.id,item.name);
        });
    });
})();